package com.shaozi.nc.server.rpc;

import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.shaozi.data.rpc.annotations.RpcMethod;
import com.shaozi.data.rpc.base.RpcResultBean;
import com.shaozi.data.rpc.server.RpcController;
import com.shaozi.lib.throwable.SzException;
import com.shaozi.nc.bean.resp.ReqListSecretaryBean;
import com.shaozi.nc.bean.resp.ReqMakeSecretaryReadByIdsBean;
import com.shaozi.nc.bean.resp.ReqMessageSetReadForTypeBean;
import com.shaozi.nc.bean.resp.ReqSecretaryTypeBadgeBean;
import com.shaozi.nc.bean.resp.ReqSecretaryUnreadMessageTotalBean;

@Component("secretaryRpcController")
@RpcMethod(prefix = "secretary")
public class SecretaryRpcController extends RpcController {

	private Logger log = Logger.getLogger(SecretaryRpcController.class);
	@Autowired
	private SecretaryRpcServer secretaryRpcServer;

	public SecretaryRpcController() {

	}

	public Map<String, Object> makeSecretaryRead(ReqMakeSecretaryReadByIdsBean reqBean) {
		RpcResultBean ret;
		try {
			ret = onServer().makeSecretaryRead(reqBean);
		} catch (SzException e) {
			ret = new RpcResultBean();
			ret.setCode(e.getCode());
		}
		return transRpcResultBean(ret);
	}

	/**
	 * 获取类型的角标即未读数,并且类型下的第一条数据
	 * 
	 * @return
	 * @throws SzException
	 */
	public Map<String, Object> getTypeBadge(ReqSecretaryTypeBadgeBean reqBean) {
		RpcResultBean ret;
		try {
			ret = onServer().getTypeBadge(reqBean);
		} catch (SzException e) {
			ret = new RpcResultBean();
			ret.setCode(e.getCode());
		}
		return transRpcResultBean(ret);
	}

	public Map<String, Object> unreadMessageTotal(ReqSecretaryUnreadMessageTotalBean reqBean) {
		RpcResultBean ret;
		try {
			ret = onServer().unreadMessageTotal(reqBean);
		} catch (SzException e) {
			ret = new RpcResultBean();
			ret.setCode(e.getCode());
		}
		return transRpcResultBean(ret);
	}

	public Map<String, Object> messageSetReadForType(ReqMessageSetReadForTypeBean reqBean) {
		RpcResultBean ret = onServer().messageSetReadForType(reqBean);

		return transRpcResultBean(ret);
	}

	public Map<String, Object> list(ReqListSecretaryBean reqBean) {
		// log.warn(new Gson().toJson(reqBean));
		RpcResultBean ret = onServer().listUpdate(reqBean);
		Map<String, Object> map = transRpcResultBean(ret);
		return map;
	}

	protected BaseSecretaryRpcServer onServer() {
		return secretaryRpcServer;
	}
}
